package com.zhuannimei.parser;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.zhuannimei.domain.Product;
import com.zhuannimei.domain.Promotion;
import com.zhuannimei.utility.UrlBank;

/***
 * 推广活动解析器
 * 
 * @author Jack 2013-12-13
 * 
 * 
 */
public class PromotionParser extends BaseJSONParser<List<Promotion>> {

	@Override
	public List<Promotion> parseJSON(String jsonstr) throws JSONException {
		List<Promotion> list = new ArrayList<Promotion>();
		JSONObject jo = new JSONObject(jsonstr);
		JSONArray jsonArray = jo.getJSONArray("result");
		for (int i = 0; i < jsonArray.length(); i++) {
			JSONObject obj = jsonArray.getJSONObject(i);
			Promotion pro = new Promotion();
			pro.setLuckId(obj.optString("luckId"));
			pro.setCgyId(obj.optString("cgyId"));
			pro.setTitle(obj.optString("title"));
			pro.setPicture(UrlBank.getServerIp()+obj.optString("picture"));
			pro.setPhase(obj.optString("phase"));
			pro.setType(obj.optString("type"));
			pro.setCtime(obj.optString("ctime"));
			list.add(pro);
		}
		return list;
	}

}
